#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>

int main()
{
	int send_fd;
	struct sockaddr_in multi_addr;
	FILE *f = fopen("data.log","r");
	char line[1024];

	send_fd = socket(AF_INET, SOCK_DGRAM, 0);
	multi_addr.sin_family = AF_INET;
	multi_addr.sin_addr.s_addr = inet_addr("224.0.0.1");
	multi_addr.sin_port = htons(9999);
printf("sending\n");
	while(fgets(line,1024,f)!=NULL)
	{
		//send line msg to multicast address
		sendto(send_fd, &line, sizeof(line), 0, (struct sockaddr*)&multi_addr, sizeof(multi_addr));
//		printf("%s\n",line);
		memset(line, 0, sizeof(line));
		usleep(10);
	}
	fclose(f);
	printf("job done~\n");
	memset(line, 0, sizeof(line));
	strcpy(line, "endendendendend\n");
	sendto(send_fd, &line, sizeof(line), 0, (struct sockaddr*)&multi_addr, sizeof(multi_addr));
	return 0;
}
